package org.agora.photogallery.client.view;

import org.agora.photogallery.client.event.ShowGalleryEvent;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.HandlerManager;

import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;


public class MainViewImpl extends Composite implements MainView {

	private static MainViewUiBinder uiBinder = GWT
			.create(MainViewUiBinder.class);

	@UiTemplate("MainView.ui.xml")
	interface MainViewUiBinder extends UiBinder<AbsolutePanel, MainViewImpl> {
	}

	@UiField
	SimplePanel collapsible;
	@UiField
	SimplePanel photoCollection;
	@UiField 
	SimplePanel photo;
	@UiField 
	FlowPanel menuPanel;
	@UiField 
	ToggleButton menuToggle;
	
	private final HandlerManager  hm;

	@Inject
	public MainViewImpl(HandlerManager  hm) {
		this.hm = hm;
		initWidget(uiBinder.createAndBindUi(this));	
	}
	
	@UiHandler("menuToggle")
	void handleClick(ClickEvent e){
		History.newItem("GalleryList");
		hm.fireEvent(new ShowGalleryEvent());
	}

	@Override
	public HasWidgets getGalleryContainer() {
		return collapsible;
	}

	@Override
	public HasWidgets getPhotoCollectionContainer() {
		return photoCollection;
	}

	@Override
	public HasWidgets getPhotoContainer() {
		return photo;
	}
	
	public Widget asWidget(){
		return this;
	}
	
	

}
